﻿/* Created by: Subodh Shrestha
 * Contact: forsubodh@gmail.com */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TravelExpertsManagementConsole
{
    public partial class frmContainer : Form
    {
        public formPackage childPackage = null;
        public formProduct childProduct = null;
        public formSupplier childSupplier = null;
        public formSupplierContact childSupplierContact = null;
        public formBooking childBooking = null;
        public Login childLogin = null;
        public Home childHomePage = null;
        public int accessLevel = -1;

        public frmContainer()
        {
            InitializeComponent();

            changeMenuItemState(false);

            childLogin = new Login(this);
            childLogin.Show();
        }

        public void changeMenuItemState(bool state)
        {
            packageToolStripMenuItem.Enabled = state;
            productToolStripMenuItem.Enabled = state;
            supplierToolStripMenuItem.Enabled = state;
            bookingToolStripMenuItem.Enabled = state;
            logoutToolStripMenuItem.Enabled = state;
            homePageToolStripMenuItem.Enabled = state;
        }

        private void packageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (childPackage == null)
            {
                childPackage = new formPackage(this);
                childPackage.Show();
            }
            childPackage.Focus();
        }

        private void productToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (childProduct == null)
            {
                childProduct = new formProduct(this);
                childProduct.Show();
            }
            childProduct.Focus();
        }

        private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            logout();
        }

        public void logout()
        {
            if (childPackage != null)
            {
                childPackage.Close();
            }
            if (childProduct != null)
            {
                childProduct.Close();
            }
            if (childSupplier != null)
            {
                childSupplier.Close();
            }
            if (childSupplierContact != null)
            {
                childSupplierContact.Close();
            }
            if (childBooking != null)
            {
                childBooking.Close();
            }
            changeMenuItemState(false);
            childLogin = new Login(this);
            childLogin.Show();
        }

        private void supplierToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (childSupplier == null)
            {
                childSupplier = new formSupplier(this);
                childSupplier.Show();
            }
            childSupplier.Focus();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void bookingToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (childBooking == null)
            {
                childBooking = new formBooking(this);
                childBooking.Show();
            }
            childBooking.Focus();
        }

        private void homePageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (childHomePage == null)
            {
                childHomePage = new Home(this);
                childHomePage.Show();
            }
            childHomePage.Focus();
        }
    }
}
